package org.jix.gbook.oss.biz.factory;

import org.apache.commons.lang3.StringUtils;
import org.jix.gbook.oss.biz.strategy.FileStrategy;
import org.jix.gbook.oss.biz.strategy.impl.AliyunOSSFileStrategyImpl;
import org.jix.gbook.oss.biz.strategy.impl.MinioFileStrategyImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author stark
 * @date 2025/6/8 12:54
 * @description
 **/
@Configuration
@RefreshScope
public class FileStrategyFactory {

    @Value("${storage.type}")
    private String strategyType;

    @Bean
    @RefreshScope
    public FileStrategy getFileStrategy(){
        if (StringUtils.equals(strategyType, "minio")) {
            return new MinioFileStrategyImpl();
        } else if (StringUtils.equals(strategyType, "aliyun")) {
            return new AliyunOSSFileStrategyImpl();
        }

        throw new IllegalArgumentException("不可用的存储类型");
    }
}
